<?php

/*%setcsname%*/
$cs_name = 'slickemp';
/*END*/

/*%setcstable%*/
$cs_table = 'slickemp';
/*END*/

session_start();
include_once "../../boot.php";
include_once $cs_name . "_fields.php";
include_once $cs_name . "_class.php";


/*%ClassCrud%*/
class employeeCrud extends CF_Crud_Pdo {
/*END*/


/*%ClassClose%*/
}
/*END*/

/*%ClassProc%*/
class employeeProcessor extends CF_ProcessorCrud {

	var $theclass = 'Employeeprocessor';

	function process_jsonlookup(){
		$col = $_REQUEST['col'];
		$lookup = new slickempLookupList;
		$list = $lookup->GetLookupList($col);
		echo json_encode($list);
		exit;
	
	}
				
	function process_list(){
		header('Location: ../mainpage.php');
	}

// process request to set filter
	function process_filter(){
				$this->GetReqFilters();
				echo json_encode($this->filters);
				
	}

	function process_jsonp(){
		$this->GetReqFilters();
		
		$lister = new slickempDataLister;
		$lister->set_filters($this->filters);

		$new_list = $lister->GetDataList();
		
		$listfiller = new slickempArray($new_list,$this->fieldspec);
		$new_list = $listfiller->fill_spec_array();
		//$new_list = $this->fill_spec_array($new_list);

		echo $_GET["jsoncallback"] . "(" . json_encode($new_list) . ")";
		exit;
		

	}
/*END*/	
	
	function process_jprow(){
		global $dbh;
		// get keys from request
		//$this->keyvalues = $this->GetReqParamsByList($this->keyvarslist,'',true);

		$this->keyvalues = $this->GetPackedParamValues('ks', 'kv');
		if(!$this->CheckArrayComplete($this->keyvalues[0], $this->keyvarslist)){
			echo 'Error Incomplete Key';
		}		
		
		
		//get row data for keys
/*%BaseQuery%*/		
		$qry_list = "SELECT * FROM employees WHERE 1=1 ";
/*END*/
		foreach($this->keyvalues[0] as $column=>$value){
			$qry_list .= ' AND ' . $column . ' = ' . ':' . $column . ' ';
		}
		$stmt = $dbh->prepare($qry_list);
		foreach($this->keyvalues[0] as $column=>$value){
			$stmt->bindParam(':' . $column, $value);
		}
	
		$stmt->execute();
		$list = $stmt->fetchAll();
		
		echo $_GET["jsoncallback"] . "(" . json_encode($list[0]) . ")";
		exit;
	
	}
	
/*%ClassClose%*/
}
/*END*/

/*%ProcSetup%*/
$proc = new employeeProcessor($slickemp_spec,$cs_name );
/*END*/
$ProcSet[$cs_name ] = $proc;

/*%CrudSetup%*/
$sd = new employeeCrud($proc);
/*END*/

$DataSourceSet[$cs_name ] = $sd;
$sd->set_processor($proc);
$sd->set_maintable($cs_table );

$proc->set_maintable($cs_table );
$proc->set_crud_class($sd);

$proc->Run();


?>

